package com.xingkeduo.business.user.service;

import com.xingkeduo.dao.database.DatabaseAccessObject;
import com.xingkeduo.pojo.query.ShareReceiveQO;
import com.xingkeduo.pojo.table.ShareReceiveTO;
import com.xingkeduo.util.pojo.exception.DataException;
import com.xingkeduo.util.tool.CommonUtil;
import com.xingkeduo.util.tool.IdentityUtil;
import com.xingkeduo.util.tool.IdentityUtil.Worker;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author:gaozifeng
 * @Date 2019/7/10 16:37
 **/
@Component
public class ShareReceiveService {
    private static final String NAMESPACE = CommonUtil.formatNamespace(ShareReceiveTO.class);
    @Resource(name = "mysqlUserMasterDao")
    private DatabaseAccessObject<ShareReceiveTO, ShareReceiveQO> dao;

    /**
     * 查询
     *
     * @param id
     * @return
     * @throws Throwable
     * @author 高杰
     * @time 2018年12月26日 下午6:26:11
     */
    public ShareReceiveTO selectByPrimary(long id) throws Throwable {
        return dao.select(NAMESPACE, id);
    }

    /**
     * 查询
     *
     * @param query
     * @return
     * @throws Throwable
     * @author 高杰
     * @time 2019年1月8日 下午2:22:21
     */
    public List<ShareReceiveTO> selectByQuery(ShareReceiveQO query) throws Throwable {
        return dao.select(NAMESPACE, query);
    }

    /**
     * 查询id集合
     *
     * @param query:
     * @return : java.util.List<java.lang.Long>
     * @author : gaozifeng
     * @date : 2019/7/5 16:35
     */
    public List<Long> selectByListId(ShareReceiveQO query) throws Throwable {
        return dao.selectIndex(NAMESPACE, query);
    }

    /**
     * 查询总数
     *
     * @param query
     * @return
     * @throws Throwable
     * @author 高杰
     * @time 2019年1月9日 下午5:06:44
     */
    public int count(ShareReceiveQO query) throws Throwable {
        return dao.selectCount(NAMESPACE, query);
    }

    /**
     * 添加
     *
     * @param table
     * @return
     * @throws Throwable
     * @author 高杰
     * @time 2018年12月27日 上午11:13:21
     */
    @Transactional
    public void insert(ShareReceiveTO table) throws Throwable {
        table.initId(IdentityUtil.nextId(Worker.USER));
        if (dao.insert(NAMESPACE, table) < 1)
            throw new DataException(DataException.Type.FAIL, "一线员工账户信息");
    }

    /**
     * 修改
     *
     * @param shareTO
     * @return
     * @throws Throwable
     * @author 高杰
     * @time 2018年12月27日 上午11:37:28
     */
    @Transactional
    public void update(ShareReceiveTO table) throws Throwable {
        if (dao.update(NAMESPACE, table) < 1)
            throw new DataException(DataException.Type.FAIL, "一线员工账户信息");
    }

}
